package com.pda.xinmazhi.presenter;

import com.pda.xinmazhi.bean.ContainerDetailBean;
import com.pda.xinmazhi.bean.LoginBean;
import com.pda.xinmazhi.bean.request.EmptyRequest;
import com.pda.xinmazhi.contract.EmptyContract;
import com.pda.xinmazhi.net.NetUtils;
import com.wangshen.base.net.bean.BaseAppEntity;
import com.wangshen.base.ui.mvp.base.presenter.BasePresenter;

import io.reactivex.functions.Consumer;

public class EmptyPresenter extends BasePresenter<EmptyContract.View> implements EmptyContract.Presenter {
    @Override
    public void getContainerDetail(String container) {
        NetUtils.geApi().getContainerDetail(container)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<ContainerDetailBean>>() {
                    @Override
                    public void accept(BaseAppEntity<ContainerDetailBean> containerDetailBeanBaseAppEntity) throws Exception {
                        getView().setData(containerDetailBeanBaseAppEntity.getData());
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void getContainerWash(String container) {
        NetUtils.geApi().getContainerWash(container)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<ContainerDetailBean>>() {
                    @Override
                    public void accept(BaseAppEntity<ContainerDetailBean> containerDetailBeanBaseAppEntity) throws Exception {
                        getView().showMessage(containerDetailBeanBaseAppEntity.getMessage());
                        getView().onClearSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void emptyIn(EmptyRequest body) {
        NetUtils.geApi().emptyIn(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<LoginBean>>() {
                    @Override
                    public void accept(BaseAppEntity<LoginBean> loginBeanBaseAppEntity) throws Exception {
                        getView().showMessage(loginBeanBaseAppEntity.getMessage());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }

    @Override
    public void emptyOut(EmptyRequest body) {
        NetUtils.geApi().emptyOut(body)
                .compose(this.handleEverythingResult())
                .subscribe(new Consumer<BaseAppEntity<LoginBean>>() {
                    @Override
                    public void accept(BaseAppEntity<LoginBean> loginBeanBaseAppEntity) throws Exception {
                        getView().showMessage(loginBeanBaseAppEntity.getMessage());
                        getView().onSuccess();
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        getView().showMessage(throwable.getMessage());
                    }
                });
    }
}
